package View;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import Controller.AddressBookController;
import Controller.ModifieContactListener;


/**
 * View to modifie  a contact
 * 
 */	

public class ModifieContactView extends JDialog{
	
	public static final String FIRSTNAME = "First name: ";
	public static final String LASTNAME= "Last Name: ";
	public static final String GROUP = "Group: " ;
	public static final String HOMEADDRESS = "Home Address: ";
	public static final String COMPANYNAME = "Company Name: ";
	public static final String COMPANYADDRESS = "Company Address: ";
	public static final String PERSPHONE = "Personal Phone: ";
	public static final String PROPHONE = "Professional Phone: ";
	public static final String WEBSITE = "Web Site: ";
	public static final String EMAIL = "Email: ";
	public static final String BIRTHDATE = "Birthdate: ";
	public static final String IMAGE = "Image: ";
	public static final String DATE ="Date: ";
	public static final String OK = "OK";
	public static final String CANCEL = "Cancel";
	
	
	private ModifieContactView that = this;
	private AddressBookController controller;
	private ModifieContactListener listener;
	
	JPanel p1,p2;
	JButton bOK,bCancel,bOpen;
	JTextField tfFirstName,tfLastName,tfGroup,tfHomeAddress,tfCompanyName,tfCompanyAddress,tfPersPhone,tfProPhone,tfWebSite,tfEmail,tfBirthDate;
	JLabel lFirstName,lLastName,lGroup,lHomeAddress,lCompanyName,lCompanyAddress,lPersPhone,lProPhone,lWebSite,lEmail,lBirthDate,lImage;

	//Default Constructor
	public ModifieContactView (AddressBookController controller) {
		
		this.controller=controller;
		this.listener= new ModifieContactListener(that,controller);
		
		//p1 with all the textField and Labels
		p1 = new JPanel();
		p1.setLayout(new GridLayout(20,2));
		p1.add(lFirstName = new JLabel(FIRSTNAME,10));
		p1.add(tfFirstName = new JTextField(controller.getContact().getFirstName(),15));
		p1.add(lLastName = new JLabel(LASTNAME,10));
		p1.add(tfLastName = new JTextField(controller.getContact().getLastName(),15));
		p1.add(lGroup = new JLabel(GROUP,10));
		p1.add(tfGroup = new JTextField(controller.getContact().getGroup(),15));
		p1.add(lHomeAddress = new JLabel(HOMEADDRESS,10));
		p1.add(tfHomeAddress = new JTextField(controller.getContact().getHomeAddress(),15));
		p1.add(lCompanyName = new JLabel(COMPANYNAME,10));
		p1.add(tfCompanyName = new JTextField(controller.getContact().getCompanyName(),15));
		p1.add(lCompanyAddress = new JLabel(COMPANYADDRESS,10));
		p1.add(tfCompanyAddress = new JTextField(controller.getContact().getCompanyAddress(),15));
		p1.add(lPersPhone = new JLabel(PERSPHONE,10));
		p1.add(tfPersPhone = new JTextField(controller.getContact().getPersPhone(),15));
		p1.add(lProPhone = new JLabel(PROPHONE,10));
		p1.add(tfProPhone = new JTextField(controller.getContact().getProPhone(),15));
		p1.add(lWebSite = new JLabel(WEBSITE,10));
		p1.add(tfWebSite = new JTextField(controller.getContact().getWebSite(),15));
		p1.add(lEmail = new JLabel(EMAIL,10));
		p1.add(tfEmail = new JTextField(controller.getContact().getEmail(),15));
		p1.add(lBirthDate = new JLabel(BIRTHDATE,10));
		p1.add(tfBirthDate = new JTextField(controller.getContact().getBirthDate(),15));
		p1.add(lImage = new JLabel("Image",10));
		p1.add(bOpen = new JButton("Open"));
		bOpen.setText(controller.getContact().getImgURL());
		
		//p2 holds the buttons
		p2 = new JPanel();
		p2.setLayout(new FlowLayout());
		p2.add(bOK = new JButton (OK));
		p2.add(bCancel = new JButton (CANCEL));
		
		//Add panels to the frame
		getContentPane().add(p1, BorderLayout.NORTH);
		getContentPane().add(p2, BorderLayout.SOUTH);
		
		//Action Listeners
		bOK.addActionListener(listener);
		bCancel.addActionListener(listener);
		bOpen.addActionListener(listener);
		
		
		
	}
	
	
	public  AddressBookController getController() {
		return controller;
	}
	
	public String getTfFirstName (){
		return tfFirstName.getText();
	}
	public String getTfLastName (){
		return tfLastName.getText();
	}
	public String getTfGroup (){
		return tfGroup.getText();
	}
	public String getTfHomeAddress (){
		return tfHomeAddress.getText();
	}
	public String getTfCompanyName (){
		return tfCompanyName.getText();
	}
	public String getTfCompanyAddress(){
		return tfCompanyAddress.getText();
	}
	public String getTfPersPhone (){
		return tfPersPhone.getText();
	}
	public String getTfProPhone(){
		return tfProPhone.getText();
	}
	public String getTfWebSite(){
		return tfWebSite.getText();
	}
	public String getTfEmail(){
		return tfEmail.getText();
	}
	public String getTfBirthDate(){
		return tfBirthDate.getText();
	}
	public void setImageName(String imageAddress){
		bOpen.setText(imageAddress);
	}
	

	
}
